home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 2000
/
MacHack 2000.toast
/
pc
/
The Hacks
/
Softshoe
/
Lisa's Mac Parts
/
TextEdit
/
TextEditObject.cp
< prev
next >
Wrap
Text File
|
2000-06-23
|
3KB
|
130 lines
// TextEditObject.cp
#ifndef TextEditObject_h
#include "TextEditObject.h"
#endif
#ifndef Overflow_h
#include "Overflow.h"
#endif
#ifndef MemoryFullError_h
#include "MemoryFullError.h"
#endif
#ifndef TooLargeForTextEdit_h
#include "TooLargeForTextEdit.h"
#endif
TextEditObject::TextEditObject( GrafPortObject& port,
const Rect& view,
uint16 wrapWidth )
{
Assert( port.IsCurrent() );
Rectangle destination( view );
Assert( CanAddSigned( destination.left, wrapWidth ) );
destination.right = destination.left + wrapWidth;
te = TENew( &destination, &view );
if ( te == 0 )
throw MemoryFullError();
Assert( *te != 0 );
Assert( Record().hText != 0 );
Assert( *Record().hText != 0 );
}
void TextEditObject::SetWrapWidth( uint16 wrapWidth )
{
Rectangle& destination( Destination() );
Assert( CanAddSigned( destination.left, wrapWidth ) );
destination.right = destination.left + wrapWidth;
}
void TextEditObject::SetScreenArea( const Rectangle& newView )
{
Rectangle& destination( Destination() );
Rectangle& view( View() );
destination += newView.TopLeft() - view.TopLeft();
view = newView;
}
void TextEditObject::DisplayAt( GrafPortObject& port,
Rectangle area,
PointObject scroll )
{
View() = area;
uint32 wrapWidth = WrapWidth();
Destination() = Rectangle( area.left - scroll.h,
area.top - scroll.v,
area.left - scroll.h + wrapWidth,
area.bottom );
(*te)->inPort = &port;
}
PointObject TextEditObject::Scroll() const
{
return PointObject( View().TopLeft() - Destination().TopLeft() );
}
void TextEditObject::SetScroll( PointObject newScroll )
{
PointObject offset = newScroll - Scroll();
if ( offset != PointObject::zero )
TEScroll( offset.h, offset.v, te );
}
void TextEditObject::ReplaceSelection( ConstData text )
{
if ( text.Length() > maxint16
|| Length() - Selection().Length() + text.Length() > maxint16 )
throw TooLargeForTextEdit();
if ( !Selection().IsEmpty() )
DeleteSelection();
TEInsert( text.Start(), text.Length(), te );
}
void TextEditObject::Type( uint8 key )
{
if ( Length() >= maxint16
&& key != backspace
&& key != leftArrow
&& key != rightArrow
&& key != upArrow
&& key != downArrow )
throw TooLargeForTextEdit();
TEKey( key, te );
}
void TextEditObject::SetText( ConstData text )
{
if ( text.Length() > maxint16 )
throw TooLargeForTextEdit();
TESetText( text.Start(), text.Length(), te );
}
void TextEditObject::DeleteForward()
{
URange16 selection = Selection();
if ( !selection.IsEmpty() )
DeleteSelection();
else
if ( selection.Start() < Length() )
{
SetSelection( URange16( selection.Start()+1,
selection.Start()+1 ) );
DeleteBackward();
}
}
void TextEditObject::SetFace( const ::Face& face )
{
SetFont( face.Font() );
SetSize( face.Size() );
SetStyle( face.Style() );
}